home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 March / Macworld (1998-03) (Disk 1).dmg / Shareware World / Utilities / Text Processing / Alpha / Tcl / Modes / browserMode.tcl < prev    next >
Encoding:
Text File  |  1997-12-10  |  4.2 KB  |  149 lines  |  [TEXT/ALFA]

  1. #=============================================================================
  2. # Browser mode.
  3. # Alpha cannot do batch searches without this file
  4. #=============================================================================
  5.  
  6. alpha::mode Brws 1.0 dummyBrws 
  7.  
  8. bind '\r'        gotoMatch    Brws
  9. bind enter        gotoMatch    Brws
  10. ascii 0x3          gotoMatch   Brws
  11. bind down         downBrowse Brws
  12. bind up         upBrowse Brws
  13. bind 'n' <z>    downBrowse Brws
  14. bind 'p' <z>    upBrowse Brws
  15. ascii 0x20        downBrowse Brws
  16. ascii 0x8        upBrowse Brws
  17. # this was below.  do we need it?
  18. bind 'c' <Cz>        gotoMatch
  19.  
  20. proc dummyBrws {} {}
  21.  
  22. proc upBrowse {} {
  23.     set limit [nextLineStart [nextLineStart 0]]
  24.     if {[getPos] > $limit} {
  25.         set limit [expr [getPos] - 1]
  26.     }
  27.     select [lineStart $limit] [nextLineStart $limit]
  28. }
  29.  
  30. proc downBrowse {} {
  31.     set pos [getPos]
  32.     if {$pos < [nextLineStart 0]} {
  33.         set pos [nextLineStart 0]
  34.     }
  35.     if {[nextLineStart $pos] != [maxPos]} {
  36.         select [nextLineStart $pos] [nextLineStart [nextLineStart $pos]]
  37.     }
  38. }
  39.  
  40. proc nextMatch {{wname "*Batch Find*"}} {
  41.     set wins [winNames]
  42.     set res [lsearch $wins $wname]
  43.     if {$res < 0} {
  44.         set res [lsearch -regexp $wins {\*.*\*}]
  45.         if {$res < 0} return
  46.     }
  47.     set win [lindex $wins $res]
  48.     bringToFront $win
  49.     downBrowse
  50.     gotoMatch
  51.     dispErr $win
  52. }
  53.  
  54. proc dispErr {{win "* Compiler Errors *"}} {
  55.     if {[string length $win]} {
  56.         set text [getText -w $win [getPos -w $win] [selEnd -w $win]]
  57.         if {[regexp {(Line.*)∞} $text dummy sub]} {
  58.             message "$sub"
  59.         }
  60.     }
  61. }
  62.         
  63.  
  64. ##############################################################################
  65. #  To be used in the windows created by "matchingLines" or by batch searches.
  66. #
  67. #  With the cursor positioned in a line corrsponding to a match, 
  68. #  go back and select the line in the original file that 
  69. #  generated this match.  (Like emacs 'Occur' functionality)
  70. #
  71. #  97-08-01 Now doesn't ask if you want a new copy of windows with <n>.
  72. #           Wrap dialog also skipped.
  73. proc gotoMatch {} {
  74.     if {[string match "*MAILBOX*" [win::CurrentTail]]} {
  75.         mailGotoMatch
  76.         return
  77.     }
  78.     global tileHeight tileWidth tileTop tileLeft tileHeight errorHeight errorDisp tileMargin
  79.     set text [getText [lineStart [getPos]] [expr [nextLineStart [getPos]] - 1]]
  80.     set ind1 [string first "∞" $text]
  81.     set ind2 [string last "∞" $text]
  82.     if {$ind1 == $ind2} {
  83.         set fname [string trim [string range $text $ind1 end] {∞}]
  84.         set msg ""
  85.     } else {
  86.         set fname [string trim [string range $text $ind1 $ind2] {∞}]
  87.         set msg [string trim [string range $text $ind2 end] {∞}]
  88.     }
  89.     
  90.     set top $tileTop
  91.     set geo [getGeometry]
  92.     if {([lindex $geo 0] != $tileLeft) || ([lindex $geo 1] != $top) || ([lindex $geo 3] != $errorHeight) } {
  93.         moveWin $tileLeft $top
  94.         sizeWin $tileWidth $errorHeight
  95.     }
  96.     set mar $tileMargin
  97.     incr top [expr $errorHeight + $mar]
  98.     if {[file exists $fname]} {
  99.         edit -c -w -g $tileLeft $top $tileWidth $errorDisp $fname
  100.         set geo [getGeometry]
  101.         if {([lindex $geo 0] != $tileLeft) || ([lindex $geo 1] != $top) || ([lindex $geo 2] != $tileWidth) || ([lindex $geo 3] != $errorDisp) } {
  102.             sizeWin $tileWidth $errorDisp
  103.             moveWin $tileLeft $top
  104.         }
  105.     } else {
  106.         if {![string match "*Link*" [getText 0 [nextLineStart 0]]]} {
  107.             alertnote "File \" $fname \" not found." 
  108.         }
  109.         return
  110.     }
  111.     if {[regexp {Line ([0-9]+):} $text dummy line]} {
  112.         set pos [rowColToPos $line 0]
  113.         select $pos [nextLineStart $pos]
  114.     }
  115.     message $msg
  116. }
  117.  
  118. set lastMatchingLines ""
  119.  
  120. proc matchingLines {{reg ""} {for 1} {ign 1} {word 0} {regexp 1}} {
  121.     global lastMatchingLines
  122.     
  123.     if {![string length $reg] && [catch {prompt "Regular expression:" $lastMatchingLines} reg]} return
  124.     set lastMatchingLines $reg
  125.     if {![string length $reg]} return
  126.     if {!$regexp} {
  127.         set reg [quote::Regfind $reg]
  128.     }
  129.     if $word {
  130.         set reg "^.*\\b$reg\\b.*$"
  131.     } else {
  132.         set reg "^.*$reg.*$"
  133.     }
  134.     set pos [expr $for ? 0 : [getPos]]
  135.     set fileName [win::Current]
  136.     set matches 0
  137.     set lines {}
  138.     while {![catch {search -s -f 1 -r 1 -i $ign $reg $pos} mtch]} {
  139.         append lines "\r" [format "Line %d: " [lindex [posToRowCol [lindex $mtch 0]] 0]] [eval getText $mtch] "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t∞$fileName"
  140.         set pos [lindex $mtch 1]
  141.         incr matches
  142.     }
  143.     grepsToWindow {* Matching Lines *} \
  144.         [format "%d matching lines (<cr> to go to match)\r-----" $matches] \
  145.         $lines "\r"
  146. }
  147.  
  148.